<%@ Control Language="C#" AutoEventWireup="true" Codebehind="ucDDLDivision.ascx.cs"
    Inherits="BaseSystem._System.UserControl.ucDDLDivision" %>
<%@ Import Namespace="Auto.Data.HumanResource" %>

<script type="text/javascript">
    function Show()
    {
        var divGVDatasState = document.getElementById('<%=divGVDatas.ClientID %>').style.display;
        document.getElementById('<%=divGVDatas.ClientID %>').style.display = (divGVDatasState == "block" ? "none" : "block");
    }
    function SetSelectedValue(obj)
    {
        var ddlDivision = document.getElementById('<%= ddlDivision.ClientID %>');
        
        for(var i=0; i<ddlDivision.options.length; i++)
        {
            if(ddlDivision.options[i].value == obj)
            {
                ddlDivision.options[i].selected = true;
                Show();
                break;
            }
        }
    }
</script>

<div style="width: 250px;">
    <table id="1" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td nowrap="nowrap">
                <asp:DropDownList ID="ddlDivision" runat="server" OnSelectedIndexChanged="ddlDivision_SelectedIndexChanged">
                </asp:DropDownList></td>
            <td nowrap="nowrap">
                <input id="btnClientSearch" type="button" onclick="Show();" value="<%=Resources.Base.Search %>" class="button_bak" /></td>
            <td nowrap="nowrap">
            </td>
        </tr>
    </table>
</div>
<div id="divGVDatas" runat="server" style="display: none; position:absolute; 
    background-color: #ffffff; border:solid 1px #4682b4">
   <!--[if lte IE 6.5]><iframe style="width:266px; height:102px; position:absolute; z-index:-1;"  frameborder="0"></iframe><![endif]-->
    <table id="2" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td >
              <%=Resources.Base.DivKeyWords %>: </td>
            <td style="width: 73px">
                <asp:TextBox ID="txtKeyWord" runat="server" Width="86px" CssClass="textcommon"></asp:TextBox></td>
            <td style="width: 32px">
            <a href="javascript:void(0)" onclick="GetDivisions(0)"><%=Resources.Base.Search %></a></td>
        </tr>
    </table>
    <div id="divisions" style="border:solid 1px #468292; margin-left:1px; margin-right:1px; margin-bottom:1px;">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="2" PageSize="2"
        GridLines="None" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnPageIndexChanging="GridView1_PageIndexChanging"
        ShowHeader="False" AllowPaging="True" OnDataBound="GridView1_DataBound">
        <FooterStyle CssClass="Footer" />
        <Columns>
            <asp:TemplateField HeaderText="<%$ Resources:Base,DivID %>" SortExpression="DivID">
                <ItemTemplate>
                    <asp:Label ID="lblDivID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, Division.FIELD_DivID).ToString() %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="100px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Base,DivName %>" SortExpression="DivName">
                <ItemTemplate>
                    <%# DataBinder.Eval(Container.DataItem, Division.FIELD_DivName).ToString() %>
                </ItemTemplate>
                <ItemStyle Width="100px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Base,Selected %>">
                <ItemTemplate>
                    <a href="javascript:void(0)" onclick="SetSelectedValue('<%# DataBinder.Eval(Container.DataItem, Division.FIELD_DivID).ToString() %>')">
                        <%=Resources.Base.Selected %></a>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerTemplate>
            &nbsp;<asp:LinkButton ID="lnkbtnPrev" runat="server" Text="<%$ Resources:Base,Prev %>"> </asp:LinkButton>
            <asp:LinkButton ID="lnkbtnNext" runat="server" Text="<%$ Resources:Base,Next %>"></asp:LinkButton>
        </PagerTemplate>
        <RowStyle CssClass="Item" />
        <EmptyDataTemplate>
            <%=Resources.Base.NoRecord %>
        </EmptyDataTemplate>
        <EditRowStyle CssClass="Edit" />
        <SelectedRowStyle CssClass="Selected" />
        <HeaderStyle CssClass="Header" Font-Bold="False" ForeColor="White" />
        <AlternatingRowStyle CssClass="Alternat" />
    </asp:GridView>
    </div>
</div>

<script type="text/javascript">

    function GetDivisions(pageIndex)
    {
        var key = document.getElementById('<%=txtKeyWord.ClientID %>').value;
        pageIndex = key + "|" + pageIndex;
        <%= Page.ClientScript.GetCallbackEventReference(this, "pageIndex", "ReceiveData", "'divisions'","ProcessCallBackError",false) %>;
    }
    
    function ReceiveData(result,context)
    {
        document.getElementById(context).innerHTML = result;
    }
    
    function ProcessCallBackError(arg,context)
    {
         alert(arg);
    }
</script>